Skip to content

Initial implementation - #1

Merged
bajtos merged 8 commits into
masterfrom
feature/extract-app-boot
May 28, 2014
Merged

Initial implementation#1
bajtos merged 8 commits into
masterfrom
feature/extract-app-boot

Conversation

@bajtos

@bajtos bajtos commented May 23, 2014

Copy link
Copy Markdown
Member

Move app.boot() and its tests from loopback.

Fix jshint warnings.

Clean up unit tests - remove dependency on global variables created
by loopback's test/support.js

/to @ritch please review.

I did not get rid of loopback.autoAttach() in this pull request, as it requires more changes.

loopback is kept as a peer dependency so that we require('loopback') works. Once we get rid of loopback.autoAttach, we should be able to remove that peer dependency too. Possibly use runtime version check instead.

Move `app.boot()` and its tests from loopback.

Fix jshint warnings.

Clean up unit tests - remove dependency on global variables created
by loopback's test/support.js
@rmg

rmg commented May 23, 2014

Copy link
Copy Markdown
Member

test please

@slnode

slnode commented May 23, 2014

Copy link
Copy Markdown

All is well
Refer to this link for build results: http://ci.strongloop.com/job/loopback-boot/2/

@bajtos

bajtos commented May 26, 2014

Copy link
Copy Markdown
Member Author

Added another commit which implements support for

  - app.json
  - app.local.{js|json}
  - app.{$env}.{js|json}

  - datasources.json
  - datasources.local.{js|json}
  - datasources.{$env}.{js|json}

@bajtos bajtos mentioned this pull request May 26, 2014
33 tasks
Modify loading of `appConfig` and `dataSourceConfig` to look for
the following files:

  - app.json
  - app.local.{js|json}
  - app.{$env}.{js|json}

  - datasources.json
  - datasources.local.{js|json}
  - datasources.{$env}.{js|json}

where $env is the value of `app.get('env')`, which usually defaults
to `process.env.NODE_ENV`.

The values in the additional files are applied to the config object,
overwritting any existing values. The new values must be value types
like String or Number; Object and Array are not supported.

Additional datasource config files cannot define new datasources,
only modify existing ones.

The commit includes refactoring of the config-loading code into
a standalone file.
@slnode

slnode commented May 27, 2014

Copy link
Copy Markdown

All is well
Refer to this link for build results: http://ci.strongloop.com/job/loopback-boot/4/

Support custom project layouts where model & datasource config files
are located in a different place from the app config.

Example:

    # API server
    server/app.config.json
    server/datasources.json

    # shared between server & client
    models.json
    models/

    # isomorphic client
    client/app.config.json
    client/datasources.json
@slnode

slnode commented May 27, 2014

Copy link
Copy Markdown

All is well
Refer to this link for build results: http://ci.strongloop.com/job/loopback-boot/6/

Miroslav Bajtoš added 3 commits May 27, 2014 16:05
No changes in functionality.
When a script in `models/` or `boot/` exports a function which is not
a loopback.Model constructor, the bootstrapper immediatelly calls
this exported function wit the current `app` object.

This is providing a dependency injection mechanism for boot scripts,
so that they no longer need to know where to find the `app` object.

Note: the dependency injection is optional. Existing code getting
`app` reference via `require('../app')` will continue to work.
@slnode

slnode commented May 27, 2014

Copy link
Copy Markdown

All is well
Refer to this link for build results: http://ci.strongloop.com/job/loopback-boot/8/

Sub-directories of `models/` and `boot/` that cannot be required
(they don't have an index.js file) are silently skipped now.

This enables developers to put test files into `models/test/`.
@slnode

slnode commented May 27, 2014

Copy link
Copy Markdown

All is well
Refer to this link for build results: http://ci.strongloop.com/job/loopback-boot/10/

@bajtos

bajtos commented May 27, 2014

Copy link
Copy Markdown
Member Author

Added more changes as required by strongloop/loopback-example-offline-sync#7.

@raymondfeng

Copy link
Copy Markdown
Member

A few high level design RFC:

  1. I think we need to organize the boot into multiple phases, such as:
    • discover/load: Find and load configurations
    • resolve/wire: Resolve the references (such as model.dataSource) and wire them together
    • startup: Initialize the datasources/models (model class can potentially have lifecycle event listeners)
    • shutdown: Emit events to notify model classes of system shutdown
    • refresh/update: React to config changes, especially additions
  2. How do we load plugin modules, for example, loopback-passport, loopback-push-notification which typically has dependencies to app and also contributes middlewares/models/datasources?
  3. Do we want to support both sync and async booting? Or eager/lazy booting?

Comment thread index.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jshint checks that all identifier are camelCase/CamelCase. Environment variables like process.env.npm_config_host are violating that rule.

The line 114 disables that check for the scope of the current method.

@ritch

ritch commented May 27, 2014

Copy link
Copy Markdown
Member

I think we need to organize the boot into multiple phases, such as:

It sounds like you are suggesting a re-design of the config loader. I think that is probably warranted for 2.0. But I think it is out of scope for this PR. All we are doing here is migrating functionality from loopback to a module and adding two new features (loading js files and env named files).

Once we migrate, we can version loopback and this new module independently and anyone can more easily adopt a 2.0 version of this module. IMO we should save larger changes for that version.

Comment thread lib/config-loader.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a formal way to document anonymous functions?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebStorm recognises it. The syntax comes from Google Closure Compiler: https://developers.google.com/closure/compiler/docs/js-for-compiler

I checked the docs again, the name:type syntax is not mentioned for functions, but they use it for record type:

{{myNum: number, myObject}} 

For functions, they have

{function(string, boolean)}
{function(this:goog.ui.Menu, string)}

@raymondfeng

Copy link
Copy Markdown
Member

Once we migrate, we can version loopback and this new module independently and anyone can more easily adopt a 2.0 version of this module. IMO we should save larger changes for that version.

Sure. I agree.

@ritch

ritch commented May 27, 2014

Copy link
Copy Markdown
Member

I don't see anything glaring. The code LGTM. I would like to see docs before I agree to the new config approach. Theres a lot going on just being pulled from old loopback, so I'm not 100% sure what new is being added.

@bajtos

bajtos commented May 28, 2014

Copy link
Copy Markdown
Member Author

I don't see anything glaring. The code LGTM.

Cool, I'll merge this pull request then.

I would like to see docs before I agree to the new config approach.

What kind of docs do you have in mind?

Theres a lot going on just being pulled from old loopback, so I'm not 100% sure what new is being added.

The first commit contains the code pulled from loopback. Everything else is new stuff.

bajtos added a commit that referenced this pull request May 28, 2014
@bajtos
bajtos merged commit 32ccacf into master May 28, 2014
@bajtos bajtos mentioned this pull request May 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants